import { Column, Entity, Index, JoinColumn, ManyToOne } from 'typeorm';
import { CommonEntity } from '~/common/entity/common.entity';
import { PointsGoodsEntity } from '../points-goods.entity';
import { UserEntity } from '~/modules/user/user.entity';

// 积分商品兑换状态枚举
export enum PointsGoodsExchangeStatus {
  PENDING = 'PENDING',           // 待处理
  APPROVED = 'APPROVED',         // 已处理
  // SHIPPING = 'SHIPPING',         // 发货中
  // SHIPPED = 'SHIPPED',           // 已发货
  COMPLETED = 'COMPLETED',       // 已完成
  CANCELLED = 'CANCELLED',       // 已取消
  REJECTED = 'REJECTED'          // 已拒绝
}

@Entity('ah_points_goods_exchange')
@Index(['id'])
export class PointsGoodsExchangeEntity extends CommonEntity {
  @Column({ type: 'varchar', length: 255, comment: '兑换标题' })
  title: string;

  @Column({ type: 'varchar', length: 255, comment: '商品图片链接' })
  imageUrl: string;

  @Column({
    type: 'enum',
    enum: PointsGoodsExchangeStatus,
    nullable: true,
    comment: '兑换状态：PENDING-待处理，APPROVED-已处理，SHIPPING-发货中，SHIPPED-已发货，COMPLETED-已完成，CANCELLED-已取消，REJECTED-已拒绝',
		default: PointsGoodsExchangeStatus.PENDING
  })
  status: PointsGoodsExchangeStatus;

  @ManyToOne(() => PointsGoodsEntity, (pointsGoods) => pointsGoods.goodsExchanges)
  @JoinColumn({ name: 'goods_id' })
  goods: PointsGoodsEntity;

	@ManyToOne(() => UserEntity, (user) => user.pointsGoodsExchanges)
	@JoinColumn({name: 'user_id'})
	user: UserEntity
}
